60

Beginner’s Guide to Code Algorithms

60

STEP 20 continued

          If PRow(k) <> ““ Then

            If PRow(k) +​ 0 =​ i Then

              PRowFound =​ 1

              Exit For

            End If

          End If

        Next k

        For k =​ 1 To 9

          If PCol(k) <> ““ Then

            If PCol(k) +​ 0 =​ j Then

              PColFound =​ 1

              Exit For

            End If

          End If

        Next k

        If PRowFound =​ 1 And PColFound =​ 0 And sbox(i, j) =​ ““ Then

          Call addtocantbelist(putnumber, i, j)

        End If

      Next j

    Next i

End If

:

:

Next putnumber

3.8  MATCHING TWINS

The second algorithm is the matching twins. This is similar to the “love-​locked pair”

algorithm we discussed earlier, but with a slight difference. The “love-​locked pair”

was a pair of cells in the same row, column, or 9 by 9 grid with the same two possible

numbers. The “love-​locked pair” helped us eliminate the numbers from other cells.

The “Matching Twin” is the cell itself which has the two possibilities. The point of

this algorithm is to discover the value of an empty cell, not “eliminate” it.

Examine the 9 by 9 matrix and find only those that have exactly two possibilities.

For each of these two-​possibility cells, fix one of the two numbers and use the rest

of the logic you have built so far to get as many blank cells as you can. Now do the

same with the other “twin” of the original two-​possibility cell. If any of the newly dis­

covered blank cells come up with the same value for both the twins, then this number

is a keeper for this blank cell. I will demonstrate this with an example.